#define _CRT_SECURE_NO_WARNINGS 1
#include "Stack.h"

void STInit(ST* pst)
{
	assert(pst);
	pst->a = NULL;
	pst->top = 0;
	pst->capacity = 0;
}

void STDestory(ST* pst)
{
	assert(pst);
	free(pst->a);
	pst->a = NULL;
	pst->capacity = 0;
	pst->top = 0;
}

void STPush(ST* pst, SlDataType x)
{
	assert(pst);
	if (pst->top == pst->capacity)
	{
		if (pst->capacity == 0)
			pst->capacity = 4;
		else
		pst->capacity *= 2;
		SlDataType* tmp = (SlDataType*)realloc(pst->a, pst->capacity*sizeof(SlDataType));
		pst->a = tmp;
	}
	pst->a[pst->top] = x;
	(pst->top)++;
}

void STPop(ST* pst)
{
	assert(pst);
	assert(!STEmpty(pst));

	pst->top--;
}

SlDataType STTop(ST* pst)
{
	assert(pst);
	assert(!STEmpty(pst));
	return pst->a[pst->top-1];
}

bool STEmpty(ST* pst)
{
	assert(pst);
	if (pst->top == 0)
		return true;
	return false;
}

int STSize(ST* pst)
{
	assert(pst);
	return pst->top;
}